package de.xt.logging.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * This class is a util to filter a given line
 * 
 * @author XT-19
 * 
 */
public class Filter {
	/**
	 * This function can be used to filter a given string after an array of
	 * patterns
	 * 
	 * @author XT-19
	 * @param line
	 *            String the string which should be filterd
	 * @param patterns
	 *            a String array which contains the patterns for which the
	 *            string should be fileted
	 * @return
	 * @throws Exception
	 */
	public String filterReplace(String line, final String[] patterns)
			throws Exception {
		if (patterns.length != 0) {
			for (String pattern : patterns) {
				line = line.replaceAll(pattern, "");
			}
			return line;
		} else
			throw new Exception("Es wurden keine Filter übergeben!");
	}

	/**
	 * This function checks if a given line
	 * 
	 * @author XT-19
	 * @param line
	 * @param regexpattern
	 * @return
	 */
	public boolean checkIfLineShouldBeFiltered(final String line, final String regexpattern) {
		Pattern pattern = Pattern.compile(regexpattern);
		Matcher matcher = pattern.matcher(line);
		return matcher.find();
	}
}
